#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

const std::string gpipeFile = "./fifo";
const mode_t gmode = 0600; 
const int gdefaultfd = -1;
const int gsize = 1024;
const int gForRead = O_RDONLY;
const int gForWrite = O_WRONLY;

class Init
{
public:
    Init(){
        int n = ::mkfifo(gpipeFile.c_str(),gmode);
        if(n < 0)
        {
            std::cerr << "mkfifo error" << std::endl;
            return;
        }
        std::cout << "mkfifo sucess" << std::endl;
        // sleep(10);
    }
    ~Init()
    {
        int n = ::unlink(gpipeFile.c_str());
        if(n < 0)
        {
            std::cerr << "unlink error" << std::endl;
            return;
        }
        std::cout << "unlink sucess" << std::endl;
    }
private:
};

int OpenPipe(int flag)
{
    //打开管道
    int fd = ::open(gpipeFile.c_str(), flag);
    if (fd < 0)
    {
        std::cerr << "open error" << std::endl; 
    }
    std::cout << "open suceess" << std::endl; 
    return fd;
}
void ClosePipeHelper(int fd)
{
    if(fd >= 0)
    {
        ::close(fd);
    }
}
